<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Currency;
use App\Models\CurrencyLog;

/**
 * 行情数据socket
 */
class MarketSocket extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'socket:market';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $btc = (new CurrencyLog())->get_index_market_data();

        $type    = 'publish';
        $content = json_encode($btc);
        $uid = 9999;
        $push_api_url = "http://114.215.40.82:2121/";
        //$push_api_url = "http://sj1.51tuanli.com/";
        $post_data = [
            "type" => $type,
            "content" => $content,
            "to" => $uid,
        ];
        //dd($post_data);
        //$post_params = http_build_query($post_data);
        //$push_api_url = "http://114.215.40.82:2121/?".$post_params;

        dump($push_api_url);

        $ch = curl_init ();

        curl_setopt ( $ch, CURLOPT_URL, $push_api_url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Expect:"));
        //dd($ch);
        $return = curl_exec ( $ch );
        curl_close ( $ch );
        dump($return);
    }
}
